<template>
	<view class="container">
		<view class="banner">
			<swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="2000" :duration="500">
				<swiper-item v-for="(item, i) in bannerList" :key="i">
					<view class="bannerImg">
						<img :src="item.pic" alt="">
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="menu">
			<view class="recommend">
				<uni-icons custom-prefix="iconfont" type="icon-yinlechangpian" size="50"></uni-icons>
				<!-- <svg class="icon" aria-hidden="true">
					<use xlink:href="#icon-yinlechangpian"></use>
				</svg> -->
				<p class="menuTxt">每日推荐</p>
			</view>
			<view class="privateFM">
				<uni-icons custom-prefix="iconfont" type="icon-shipin" size="50"></uni-icons>
				<!-- <svg class="icon" aria-hidden="true">
					<use xlink:href="#icon-shipin"></use>
				</svg> -->
				<p class="menuTxt">私人FM</p>
			</view>
			<view class="songSheet">
				<uni-icons custom-prefix="iconfont" type="icon-faxian" size="50"></uni-icons>
				<!-- <svg class="icon" aria-hidden="true">
					<use xlink:href="#icon-faxian"></use>
				</svg> -->
				<p class="menuTxt">歌单</p>
			</view>
			<view class="rankingList">
				<uni-icons custom-prefix="iconfont" type="icon-yinlequan" size="50"></uni-icons>
				<!-- <svg class="icon" aria-hidden="true">
					<use xlink:href="#icon-yinlequan"></use>
				</svg> -->
				<p class="menuTxt">排行榜</p>
			</view>
		</view>
		<view class="findSongSheet">
			<view class="findTitle">
				<h3>发现好歌单</h3>
				<p>查看更多</p>
			</view>
			<view class="scrollView">
				<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="120">
					<view id="demo1" class="scroll-view-item_H uni-bg-red" v-for="(item, i) in SongSheetList" :key="i" @click="changeNavigate(item)">
						<view class="scrollItem">
							<view class="picUrl">
								<img :src="item.picUrl" alt="">
							</view>
							<p>{{item.name}}</p>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<audioPlayer></audioPlayer>
	</view>
</template>

<script>
	import audioPlayer from 'components/audioPlayer/audioPlayer.vue'
	export default {
		data() {
			return {
				bannerList: [],
				SongSheetList: []
			}
		},
		components: {audioPlayer},
		onLoad() {
			this.getBannerList()
			this.getFindSongSheet()
		},
		methods: {
			changeNavigate(item) {
				uni.navigateTo({
					url: '/pages/itemMusic/itemMusic?id=' + item.id
				})
			},
			async getBannerList() {
				const {
					data: res
				} = await this.$myRequest({
					url: '/banner?type=2'
				})
				for (let i = 0; i < res.banners.length; i++) {
					this.bannerList.push({
						pic: res.banners[i].pic
					})
				}
			},
			async getFindSongSheet() {
				const {
					data: res
				} = await this.$myRequest({
					url: '/personalized?limit=30'
				})
				this.SongSheetList = res.result
				// console.log(this.SongSheetList);
			}
		}
	}
</script>

<style lang="less">
	* {
		margin: 0;
		padding: 0;
	}

	.container {
		width: 750rpx;
		margin: 0 auto;

		.banner {

			.swiper {
				height: 370rpx;

				.bannerImg {
					padding: 20rpx 20rpx;
					// width: 710rpx;
					width:95%;
					height: 350rpx;

					img {
						border-radius: 20rpx;
						width: 100%;
						height: 100%;
					}
				}
			}
		}

		.menu {
			height: 200rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;

			view {
				// border: 1px solid red;
				width: 180rpx;
				height: 180rpx;
				padding: 20rpx 0;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
			}

			.icon {
				width: 80rpx;
				height: 80rpx;
				margin-left: 50rpx;
				margin-top: 20rpx;
			}

			.menuTxt {
				text-align: center;
			}

		}

		.findSongSheet {
			padding: 0 20rpx;

			.findTitle {
				height: 60rpx;
				line-height: 60rpx;
				display: flex;
				justify-content: space-between;

				p {
					border-radius: 50rpx;
					border: 1px solid #ccc;
					width: 180rpx;
					text-align: center;
				}
			}
		}

		.scrollView {
			margin-top: 20rpx;

			.scroll-view_H {
				white-space: nowrap;
				width: 100%;
			}

			.scroll-view-item_H {
				display: inline-block;
				width: 250rpx;
				// height: 400rpx;
				text-align: center;
				font-size: 36rpx;
				padding: 10rpx 10rpx;

				.scrollItem {
					display: flex;
					flex-direction: column;

					.picUrl {
						width: 250rpx;
						height: 250rpx;

						img {
							border-radius: 20rpx;
							width: 100%;
							height: 100%;
						}
					}

					p {
						font-size: 24rpx;
						margin-top: 10rpx;
						overflow: hidden;
						white-space: break-spaces; //文字换行
						text-align: left;
						text-overflow: ellipsis;
						// display: -webkit-box;
						// -webkit-box-orient: vertical;
						// -webkit-line-clamp: 2;
					}
				}

			}
		}
	}
</style>
